//
//  CPUserManager.m
//  CPBaseXCode
//
//  Created by cp on 2024/9/19.
//

#import "CPUserManager.h"
#import <MMKV/MMKV.h>

#define user_info    @"__userinfo__"

@interface CPUserManager ()

@property (nonatomic,strong)MMKV *myMMkv;

@end

@implementation CPUserManager
+(instancetype)shareManger
{
    static CPUserManager *manger = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manger =  [[CPUserManager alloc]init];
        
    });
    return manger;
}

-(instancetype)init
{
    self = [super init];
    if (self) {
        //需要再APPdelegate [MMKV initializeMMKV:nil];
        self.myMMkv = [MMKV defaultMMKV];
//        [self getUserInfo];
    }
    return self;
}
-(BOOL)isLogin
{
    if([self.myMMkv getObjectOfClass:[NSDictionary class] forKey:user_info]){
        return YES;
    }
    return NO;
}
-(void)clearInfo
{
    [MMKV initializeMMKV:nil];
    [self.myMMkv removeValueForKey:user_info];
//    self.userInfo = nil;
    
}
@end
